﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Constant;

namespace Pixysoft.Weblications.Sango.Command.party
{
    partial class SangoPartyHandler
    {
        public party_memberkick party_memberkick(string memberusercode)
        {
            string userCode = SangoManager.Authentication();

            party_memberkick response = ReflectionManager.CreatePojo<party_memberkick>();
            response.Succeed = false;


            Entities.Usr_Partymember myMember = PartyDao.tryGetActiveMember(userCode);

            if (myMember == null)
            {
                response.Message = "尚未加入军团";
                return response;
            }

            Entities.Usr_Partymember targetMember = PartyDao.tryGetActiveMember(memberusercode);

            if (targetMember == null)
            {
                response.Message = "对方尚未加入军团";
                return response;
            }

            if (!myMember.Partyprimarycode.Equals(targetMember.Partyprimarycode, StringComparison.OrdinalIgnoreCase))
            {
                response.Message = "双方不在相同的军团";
                return response;
            }

            if (myMember.Titletypecode < PtyTitleSerialcodeCollection.POSITION_VICE_PRESIDENT)
            {
                response.Message = "权限不足";
                return response;
            }

            if (myMember.Titletypecode < targetMember.Titletypecode)
            {
                response.Message = "权限不足2";
                return response;
            }

            Entities.Usr_Party party = PartyDao.tryGetActiveParty(targetMember.Partyprimarycode);

            PartyDao.quitParty(party, targetMember);

            IEntityNoebeTransaction transaction = SettingHelper.EntityTransaction;
            transaction.Begin(delegate()
            {
                transaction.Update(party);

                transaction.Update(targetMember);

                transaction.Commit();
            });

            response.Succeed = true;
            return response;
        }


    }
    public interface party_memberkick : ISangoResponse
    {
    }
}
